<?php

declare(strict_types=1);

namespace app\common\service\crm;

use app\common\traits\ServiceTrait;
use app\common\dao\crm\ContractProductDao;


/**
 * 联系人表 服务业务层(Service)
 * @author 吕玉冰
 * @date  2022-07-21
 * @copyright ©2022 泉州市盛筑信息科技有限公司 版权所有
 */
class ContractProductService
{
    protected $dao = null;

    public function __construct()
    {
        $this->dao = new ContractProductDao();
    }

    use ServiceTrait;

    public function _list_format($data)
    {
        foreach ($data as $k => $v) {
            $temp = [];
            $temp = explode(",", $v['product_part_id']);
            foreach ($temp as $k2 => $v2) {
                $data[$k]['part_list'][$k2]['product_part_id'] = $v2;
            }
            $temp = [];
            $temp = explode(",", $v['product_part_id_num']);
            foreach ($temp as $k2 => $v2) {
                $data[$k]['part_list'][$k2]['product_part_id_num'] = $v2;
            }
        }

        return $data;
    }


    public function _list_where($data)
    {
        $where = [];
        if (isset($data['ids']) && !empty($data['ids'])) {
            $where[] = ["id", "in", $data['ids']];
        }
        $data['where'] = $where;
        return [
            'where' => isset($data['where']) ? $data['where'] : [],
            'order' => ['id' => 'asc'],
            'field' => isset($data['field']) ? $data['field'] : ['*'],
        ];
    }


    public function saveAll($data)
    {
        $redata = $this->dao->focusAdd($data);
        return $redata;
    }


}